package com.ruanxie.service.impl;

import com.ruanxie.constant.MessageConstant;
import com.ruanxie.dto.user.UserLoginDTO;
import com.ruanxie.entity.User;
import com.ruanxie.exception.AccountNotFoundException;
import com.ruanxie.mapper.UserMapper;
import com.ruanxie.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    /**
     * 用户登录
     * @param userLoginDTO
     * @return
     */
    @Override
    public User login(UserLoginDTO userLoginDTO) {
        User selectUser=new User();
        BeanUtils.copyProperties(userLoginDTO,selectUser);
        User user=userMapper.get(selectUser);
        //处理账号找不到的异常
        if(user==null){
            throw new AccountNotFoundException(MessageConstant.ACCOUNT_NOT_FOUND);
        }
        return user;
    }
}
